package com.stupro.cjlu.controller;


import com.stupro.cjlu.common.utils.VOToEntity;
import com.stupro.cjlu.common.vo.ResultVO;
import com.stupro.cjlu.common.vo.StudentItemVO;
import com.stupro.cjlu.entity.Students;
import com.stupro.cjlu.service.CourseService;
import com.stupro.cjlu.service.StudentsService;
import com.stupro.cjlu.service.TeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2021-05-10
 */
@RestController
@RequestMapping("/students")
public class StudentsController extends  BaseController {


    @Autowired
    private StudentsService studentsService;

    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    @ApiOperation("可选选课总数")
    @GetMapping("/getCourseCount")
    public ResultVO getCourseCount(Integer teaID,String name) {
        return courseService.getPageCount(teaID,name);
    }

    @ApiOperation("查询成绩")
    @GetMapping("/getGrade")
    public ResultVO getGrade(Integer studentID){
        return studentsService.getGrade(studentID);
    }

    @ApiOperation("更新学生信息")
    @PostMapping("/updata")
    public ResultVO updata(StudentItemVO students){
        Students student = VOToEntity.toStudent(students);
        return studentsService.update(student);
    }

    @ApiOperation("选课")
    @GetMapping("/chooseCourse")
    public ResultVO chooseCourse(Integer studentID,Integer courseID) {
        return studentsService.chooseCourse(studentID, courseID);
    }

    @ApiOperation("获取课程")
    @GetMapping("/getCourse")
    public ResultVO studentGetCourse(Integer page,String teaName,String className){
        return teacherService.getCourse(page, teaName, className);
    }

    @ApiOperation("获取选课课程")
    @GetMapping("/getCourseSelected")
    public ResultVO studentCourseSelected(Integer studentID){
        return studentsService.getSelectedCourse(studentID);
    }

    @ApiOperation("退选")
    @GetMapping("delCourseSelected")
    public ResultVO deleteCourseSelected(Integer scID){
        return studentsService.deleteByScId(scID);
    }



}
